﻿using System;
using System.Collections.Generic;
using System.Text;

namespace BlogDemo.Common
{
    public abstract class DisposableBase : IDisposable
    {
        #region Finalization Constructs
        /// <summary>
        /// Finalizes the object.
        /// </summary>
        ~DisposableBase()
        { 
            // 请勿更改此代码。将清理代码放入以上 Dispose(bool disposing) 中。
            this.Dispose(false);
        }
        #endregion

        #region IDisposable Support
        private bool disposedValue = false;  // 要检测冗余调用

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    // TODO: dispose managed state (managed objects).
                }

                // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below.
                // TODO: set large fields to null.

                disposedValue = true;
            }
        }

        // TODO: override a finalizer only if Dispose(bool disposing) above has code to free unmanaged resources.
     
        // This code added to correctly implement the disposable pattern.
        void IDisposable.Dispose()
        {           
            // 请勿更改此代码。将清理代码放入以上 Dispose(bool disposing) 中。
            // Do not change this code. Put cleanup code in Dispose(bool disposing) above.
            Dispose(true);
            // TODO: uncomment the following line if the finalizer is overridden above.
            GC.SuppressFinalize(this);
        }
        #endregion
    }
}
